Homework 1

I am going to produce a string called mary had a little lamb in one code block. Then I am going to split the string to one word per row. Then I am going to add a variable called Nletters that counts the letters in each word. The other part of my homework is to style my css to my personal needs.

Practice

#this is a code block - to get this, hit green "C" at top and select R

#print a sequence of numbers 1:10
myseq <- seq(1:10)
print(myseq)
##  [1]  1  2  3  4  5  6  7  8  9 10

Assignment

Step 1 - mary had a little lamb

#load mary had a little lamb text
  marydat <- paste("Mary had a little lamb")

#paste text
  paste(marydat)
## [1] "Mary had a little lamb"

Step 2 - split words into line

#create data frame with variable "word" that splits mary had a little lamb into one word per line
  df <- data.frame(
    word = unlist(strsplit(marydat, "\\s+"))
  )

#print data frame
  print(df)
##     word
## 1   Mary
## 2    had
## 3      a
## 4 little
## 5   lamb

Step 3 - get letter count

#create new variable variable "Nletters" that counts letters in each word
  df$Nletters <- nchar(df$word)

#print data frame
  print(df)
##     word Nletters
## 1   Mary        4
## 2    had        3
## 3      a        1
## 4 little        6
## 5   lamb        4